package epidemic

import (
	"gitee.com/baal1990/epidemic/global"
	response "gitee.com/baal1990/epidemic/model/common/response_dfitc"
	epidemicReq "gitee.com/baal1990/epidemic/model/epidemic/request"
	"gitee.com/baal1990/epidemic/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

type EpidemicInvestigationDetailsApi struct {
}

var epidemicInvestigationDetailsService = service.ServiceGroupApp.EpidemicServiceGroup.EpidemicInvestigationDetailsService

// GetEpidemicInvestigationDetailsList 分页获取EpidemicInvestigationDetails列表
// @Tags EpidemicInvestigationDetails
// @Summary 分页获取EpidemicInvestigationDetails列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query epidemicReq.EpidemicInvestigationDetailsSearch true "分页获取EpidemicInvestigationDetails列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /epidemicInvestigationDetails/getEpidemicInvestigationDetailsList [get]
func (epidemicInvestigationDetailsApi *EpidemicInvestigationDetailsApi) GetEpidemicInvestigationDetailsList(c *gin.Context) {
	var pageInfo epidemicReq.EpidemicInvestigationDetailsSearch
	_ = c.ShouldBindQuery(&pageInfo)
	global.GVA_LOG.Info("请求参数", zap.Any("param", pageInfo))
	if list, total, err := epidemicInvestigationDetailsService.GetEpidemicInvestigationDetailsInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

func (epidemicInvestigationDetailsApi *EpidemicInvestigationDetailsApi) ExportAll(c *gin.Context) {
	id := c.DefaultQuery("id", "")
	u64, err := strconv.ParseUint(id, 10, 32)
	if err != nil {
		response.FailWithMessage("参数错误", c)
		return
	}
	fileName, err := epidemicInvestigationDetailsService.ExportAll(uint(u64))
	if err != nil {
		global.GVA_LOG.Error("导出失败!", zap.Error(err))
		response.FailWithMessage("导出失败", c)
	} else {
		fileLinck := global.GVA_CONFIG.System.AccessHost + fileName
		response.OkWithData(fileLinck, c)
	}
}
